package com.agent.vpsserver.modules.server.service.impl;

import com.agent.vpsserver.common.dto.PageBean;
import com.agent.vpsserver.common.utils.mapping.BeansUtils;
import com.agent.vpsserver.modules.server.entity.pojo.SmsInfoDO;
import com.agent.vpsserver.modules.server.mapper.SmsInfoMapper;
import com.agent.vpsserver.modules.server.request.SmsInfoPageRequest;
import com.agent.vpsserver.modules.server.response.SmsInfoPageResponse;
import com.agent.vpsserver.modules.server.service.SmsInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 短信信息(SmsInfo)表服务实现类
 *
 * @author guochao
 * @since 2024-03-29 12:02:29
 */
@Service("smsInfoService")
public class SmsInfoServiceImpl extends ServiceImpl<SmsInfoMapper, SmsInfoDO> implements SmsInfoService {

    @Override
    public PageBean<SmsInfoPageResponse> pageData(SmsInfoPageRequest request) {
        PageHelper.startPage(request.getPageNum(), request.getPageSize(), true);
        LambdaQueryWrapper<SmsInfoDO> queryWrapper = new LambdaQueryWrapper<SmsInfoDO>()
                .eq(StringUtils.isNotBlank(request.getPhone()), SmsInfoDO::getPhone, request.getPhone())
                .eq(StringUtils.isNotBlank(request.getUniqueCode()), SmsInfoDO::getUniqueCode, request.getUniqueCode());
        List<SmsInfoDO> smsInfoDOS = baseMapper.selectList(queryWrapper);
        PageBean<SmsInfoPageResponse> pageBean = new PageBean<>();
        pageBean.setPageInfo(smsInfoDOS);
        pageBean.setList(BeansUtils.mapList(smsInfoDOS, SmsInfoPageResponse.class));
        return pageBean;
    }
}

